﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class UEnumerator : IEnumerable
    {
        List<int> data = new List<int>();
        public IEnumerator GetEnumerator()
        {
            Enumerator enumerator = new Enumerator(this);
            return enumerator;
        }
        public void Add(int i)
        {
            data.Add(i);
        }

        class Enumerator : IEnumerator, IDisposable
        {
            int position;
            List<int> data;

            public Enumerator(UEnumerator hc)
            {
                data = hc.data;
            }
            public object Current
            {
                get { return data[position - 1]; }
            }
            public bool MoveNext()
            {
                if (position < data.Count)
                {
                    position++;
                    return true;
                }
                return false;
            }

            public void Reset()
            {
                position = 0;
            }

            public void Dispose()
            {

            }
        }
    }

    public class UEnumerator2 : IEnumerable
    {
        List<int> data = new List<int>();
        public IEnumerator GetEnumerator()
        {
            for (int i = 0; i < data.Count; i++)
            {
                if (i > 5)
                    yield break;
                yield return data[i];
            }
        }
        public void Add(int i)
        {
            data.Add(i);
        }
    }
}
